//
//  PasswordViewController.m
//  LFCWarmSystem
//
//  Created by 李振文 on 16/4/25.
//  Copyright © 2016年 李福才. All rights reserved.
//

#import "PasswordViewController.h"
#import "UIViewController+extension.h"
#import "StartPSWViewController.h"
@interface PasswordViewController ()<UIGestureRecognizerDelegate>{
    UIScrollView *mainView;
    UIButton *btnStart;
    UIButton *btnClose;
}

@end

@implementation PasswordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setTitle:NSLocalizedString(@"WarmSystem_Sample",@"报警系统") leftBarItemsTitle:@[NSLocalizedString(@"Back_Sample",@"返回")] rightBarItemsTitle:nil];
    [self uiInit];
    
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    if (![[DBOperation getDBOperateInstance] selectPassWord]) {
        UITapGestureRecognizer *tapGestureStart = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(startGesture:)];
        tapGestureStart.numberOfTouchesRequired = 1;
        tapGestureStart.delegate = self;
        [btnStart addGestureRecognizer:tapGestureStart];
        [btnClose setBackgroundImage:[UIImage imageNamed:@"selected.png"] forState:UIControlStateNormal];
        [btnClose setBackgroundImage:[UIImage imageNamed:@"selected.png"] forState:UIControlStateHighlighted];
        [btnStart setBackgroundImage:[UIImage imageNamed:@"unselected.png"] forState:UIControlStateNormal];
        [btnStart setBackgroundImage:[UIImage imageNamed:@"unselected.png"] forState:UIControlStateHighlighted];
    }else{
        UITapGestureRecognizer *tapGestureClose = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeGesture:)];
        tapGestureClose.numberOfTouchesRequired = 1;
        tapGestureClose.delegate = self;
        [btnClose addGestureRecognizer:tapGestureClose];
        [btnStart setBackgroundImage:[UIImage imageNamed:@"selected.png"] forState:UIControlStateNormal];
        [btnStart setBackgroundImage:[UIImage imageNamed:@"selected.png"] forState:UIControlStateHighlighted];
        [btnClose setBackgroundImage:[UIImage imageNamed:@"unselected.png"] forState:UIControlStateNormal];
        [btnClose setBackgroundImage:[UIImage imageNamed:@"unselected.png"] forState:UIControlStateHighlighted];
    }
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
-(void)uiInit{
    self.automaticallyAdjustsScrollViewInsets = NO;
    mainView = [[UIScrollView alloc] initWithFrame:CGRectMake(10*WIDTHSCALE, 64+20*WIDTHSCALE, self.view.frame.size.width-2*10*WIDTHSCALE, self.view.frame.size.height-64-2*20*WIDTHSCALE-44*WIDTHSCALE)];
    mainView.layer.cornerRadius = 5.0;
    mainView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:mainView];
    
    UILabel *lblMain = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, mainView.frame.size.width, mainView.frame.size.height/5.0)];
    lblMain.text = NSLocalizedString(@"PassWord_Sample", @"密码");
    lblMain.textAlignment = NSTextAlignmentCenter;
    lblMain.textColor = COLOR_MAINHEAD;
    lblMain.font = TABLEHEADFONT;
    [mainView addSubview:lblMain];
    
    btnStart = [UIButton buttonWithType:UIButtonTypeCustom];
    btnStart.frame = CGRectMake(10, lblMain.frame.origin.y+lblMain.frame.size.height, mainView.frame.size.width-2*10*WIDTHSCALE, TEXTHEIGHT);
    btnStart.layer.cornerRadius = 5.0;
    btnStart.layer.masksToBounds = YES;
    [btnStart setTintColor:BLACKCOLOR];
    btnStart.userInteractionEnabled = YES;
    btnStart.titleEdgeInsets = UIEdgeInsetsMake(0,30*WIDTHSCALE-btnStart.frame.size.width/2.0, 0, -30*WIDTHSCALE+btnStart.frame.size.width/2.0);
    [btnStart setTitle:NSLocalizedString(@"Start_Sample", @"开启") forState:UIControlStateNormal];
    [mainView addSubview:btnStart];
    

    btnClose = [UIButton buttonWithType:UIButtonTypeCustom];
    btnClose.frame = CGRectMake(btnStart.frame.origin.x, btnStart.frame.origin.y+btnStart.frame.size.height+20*WIDTHSCALE, btnStart.frame.size.width, btnStart.frame.size.height);
    btnClose.layer.cornerRadius = 5.0;
    btnClose.layer.masksToBounds = YES;
    [btnClose setTintColor:BLACKCOLOR];
    btnClose.userInteractionEnabled = YES;
    btnClose.titleEdgeInsets = UIEdgeInsetsMake(0,30*WIDTHSCALE-btnClose.frame.size.width/2.0, 0, -30*WIDTHSCALE+btnClose.frame.size.width/2.0);
    [btnClose setTitle:NSLocalizedString(@"Close_Sample", @"关闭") forState:UIControlStateNormal];
    [mainView addSubview:btnClose];
}



-(void)startGesture:(UIGestureRecognizer*)gesture{
    NSLog(@"start Gesture");
    StartPSWViewController *startVC = [[StartPSWViewController alloc] init];
    startVC.startPSW = YES;
    [self.navigationController pushViewController:startVC animated:YES];
}
-(void)closeGesture:(UIGestureRecognizer*)gesture{
    NSLog(@"close Gesture");
    StartPSWViewController *closeVC = [[StartPSWViewController alloc] init];
    closeVC.startPSW = NO;
    [self.navigationController pushViewController:closeVC animated:YES];
}

@end
